/*
 * @Author: szx
 * @Date: 2022-03-07 13:25:10
 * @LastEditTime: 2022-03-07 13:32:40
 * @Description:
 * @FilePath: \leetcode\1400-1499\1409\1409.js
 */
/**
 * @param {number[]} queries
 * @param {number} m
 * @return {number[]}
 */
var processQueries = function (queries, m) {
    const arr = new Array(m).fill(0).map((value, index) => (value = index + 1));
    const res = [];
    for (let q of queries) {
        const index = arr.indexOf(q);
        for (let i = index - 1; i >= 0; i--) {
            arr[i + 1] = arr[i];
        }
        arr[0] = q;
        res.push(index);
    }
    return res;
};

console.log(processQueries([3, 1, 2, 1], 5));
